/*单个产品删除*****/
function  delete_info(id,tr_id,act_type)
{
	if(act_type == 'del')
	{
		$.get("/wondershare/product_m_list.php?action=index", { in_jax: 1,p_id:id, type: act_type ,value:1},
		function(data){
			if(data == 1)
			{
				$("#"+tr_id).remove();
				$('#total').html(parseInt($('#total').html())-1) ;
			}else
			{
				alert('删除失败!');
			}
		});
	}

}
/*批量产品删除*/
function  delete_product(ar_id,type,act_type)
{
	var str = "";
	var tips = '确定删除记录吗?';
	var falge = false;
	$('input[name="ID[]"]').each(function () 
	{
		if ($(this).attr('checked')) 
		{
			falge = true; 
			str += $(this).val() + ",";
		}
	});
	if(!falge)
	{ 
		alert('你没有选择任何选项！');  
		return false;
	}
	if(confirm(tips))
	{ 
		if(act_type == 'del_products')
		{
			$.get("/wondershare/product_m_list.php?action=index", { in_jax: 2, checkList: str ,type:'del_products'},
			function(data){});  
		}
		$('input[name="ID[]"]').each(function () {
			if ($(this).attr('checked')) 
			{
				$("#tr_"+$(this).val()).remove();
				$('#total').html(parseInt($('#total').html())-1) ;
			}
		}); 
	}
}


function tab()
{
	$('#tab_info').find("span").mouseover(function()
	{
		$('#tab_info').find("span").removeClass("tab-front");
		$('#tab_info').find("span").addClass("tab-back");
		$(this).removeClass("tab-back");
		$(this).addClass("tab-front");
		var target = $('#' + this.id+'le');
		if (target.size() > 0) 
		{
			$('#tabbody-div').find("table").hide();
			target.show();
		} 
	}); 

}

function create_FCKedito(value)
{
	var oFCKeditor          = new FCKeditor(value);      //创建FCK对象
	oFCKeditor.Height      = 400;        //设置FCK显示高度
	oFCKeditor.Width      = 750;        //设置FCK显示宽度
	oFCKeditor.BasePath   = "../../fckeditor/";    //指定编辑器路径，要加载fckeditor/editor/fckeditor.html
	oFCKeditor.ReplaceTextarea(); 
}

function create()
{
	tab();
}

function GetCBSDate()
{
	var product_cbsid = $("#product_cbsid").val();
	var form_action=$("#product_form").attr("action");
	if(product_cbsid.replace(/(^\s*)|(\s*$)/g, "")!="")
	{
	$("#product_sn").val("");
	$("#product_version").val("");
	$("#product_name").val("");
	$("#product_price").val("");
	$("#product_brand").val("")
	
	$.post("./product.php?action=GetCBSData",{pcbs_id:product_cbsid,form_action:'./product.php?action=AddProduct'},function(data)
	{
		var product_date=data;
		if(product_date['message']=='success')
		{
			$("#product_sn").val(product_date['product_sn']);
			$("#product_version").val(product_date['sale_version']);
			$("#product_name").val(product_date['product_name']);
			$("#product_price").val(product_date['price']);
			$("#product_brand").val(product_date['brand_name']);
		}
		else
		{
			alert(product_date['message']);
			$("#product_cbsid").val('');
			$("#product_cbsid").focus();
		}
	},'json');
	}
	else
	{
		alert("请输入CBS产品ID!");
		$("#product_cbsid").focus();
	
	}
}

function save_product()
{
	if(Util.ValiForm.formValiState())
	{
		$("#product_form").submit();
	}
}

function reset_product()
{
	$("#product_cbsid").attr("readonly","");
}
	
function getproductlist(type)
{
	
	var products_id = $("#products_id").val();
	if(type == 'products_id')
	{
		var product_list = $("#hidden_products_id").val();
		jIframe('', '所有产品列表', {
		width: 750,
		height: 345,
		src: './product.php?action=RecommProductTwo&product_list='+product_list,
		ID: 'all_product',
		box_btn:true,
		callback:add_okbtn
		});
	}else if(type == 'm_product_recomm')
	{
		var product_list = $("#h_m_product_recomm").val();
		jIframe('', '所有ws产品列表', {
		width: 850,
		height: 345,
		src: './product_m_list.php?action=index&type=1&product_list='+product_list+'&products_id='+products_id,
		ID: 'all_product',
		box_btn:true,
		callback:add_okbtn_tow
		});
	}
	
}
	
function add_okbtn()
{
	var id = document.getElementById("all_product").contentWindow.get_checked_product();
	var name = document.getElementById("all_product").contentWindow.get_checked_product_name();
	$("#hidden_products_id").val(id);
	var fage = 0;
	jClose();
	$.ajax({
	type: "GET",
	url: "/wondershare/product_m_list.php?action=index",
	async: false,
	data:"in_jax=2&p_id="+$('#hidden_products_id').val(),
	success: function(data)
	{
		if(data == 1)
		{
			alert('你要增加的ws产品已经存在库中，请重新选择！');
			$("#products_id").val('');
			$('#hidden_products_id').val('');
			fage = 1;
		}
	}
	});
	if(fage == 0)
	{
		$("#products_id").val(name);
	}else
	{
		$("#products_id").val('');
	}

}

function add_okbtn_tow()
{
	var id = document.getElementById("all_product").contentWindow.get_checked_product();
	var name = document.getElementById("all_product").contentWindow.get_checked_product_name();
	$("#m_product_recomm").val(name);
	$("#h_m_product_recomm").val(id);
	
	jClose();
}


function  add_feature(type)
{
	$('#button_feature').css('margin-left','0px');
	$('#button_more_feature').css('margin-left','0px');	 
	if(type == 1)
	{
		var feature_start = parseInt($("#feature_start").val())+1; 
		
		$('#add_feature').before('<tr ><td ><div style="margin-left:200px; width:120px; margin-top:40px;">Key Feature'+feature_start
		+'标题：</div></td>'+
		'<td ><input type="text" style="width:400px;margin-top:30px; " id="title_feature'+feature_start+'" name="title_feature'+
		feature_start+'" /></td>'+
		'</tr><tr ><td ><div style="margin-left:200px; width:150px; margin-top:20px;"><span style="">Key Feature'+feature_start+'描述：'+
		'</span><br /><br /></div></td>'+
		'<td ><textarea size="50"    value="" style="margin-left:0px;margin-top:10px; width:400px; height:80px;'+
		'overflow:hidden; " id="description_feature'+feature_start+'" name="description_feature'+
		feature_start+'"/> </textarea></td></tr><tr ><td >'+
		'<div style="margin-left:200px; width:120px; margin-top:20px;">Key Feature'+feature_start+'小配图：</div></td><td >'+
		'<input type="text"  style="width:400px; margin-top:20px;" id="image_min_feature'+feature_start+'" name="image_min_feature'+
		feature_start+'"/>'+
		'<span style="color:#FF0000; margin-left:20px;margin-top:20px;">(备注：请填写URL绝对地址)</span></td> </tr><tr ><td >'+
		'<div style="margin-left:200px; width:120px; margin-top:20px;">Key Feature'+feature_start+'大配图：</div></td><td ><input type="text" '+
		'  style="width:400px;margin-top:20px; " id="image_max_feature'+feature_start+'" name="image_max_feature'+feature_start+'" />'+
		'<input type="hidden" name="feature_id'+feature_start+'" value="0" /><span style="color:#FF0000; margin-left:20px;margin-top:20px;">'+
		'(备注：请填写URL绝对地址)</span></td></tr>'); 
		
		$("#feature_start").val(feature_start);
		if(feature_start == 11)
		{
			$("#add_feature").css('display','none');
		}
	}else if(type == 2)
	{
		var more_feature_start = parseInt($("#more_feature_start").val())+1; 
		$('#add_more_feature').before('<tr ><td ><div style="margin-left:200px; width:120px; margin-top:50px;">More Feature'+more_feature_start+
		'标题：</div></td><td ><input type="text" name="title_more_feature'+more_feature_start+'" id="title_more_feature'+more_feature_start+
		'" style="width:400px; margin-top:40px;" /></td></tr><tr ><td ><div style="margin-left:200px; width:150px; margin-top:20px;">'+
		'<span style="">More Feature'+more_feature_start+'描述：</span></div></td><td ><textarea name="description_more_feature'+more_feature_start+
		'" id="description_more_feature'+more_feature_start+'" size="50" style="margin-left:0px;margin-top:10px; width:400px; '+	
		'height:70px;overflow:hidden; " /> </textarea></td></tr> <tr ><td ><div style="margin-left:200px;width:120px; margin-top:20px;">'+
		'More Feature'+more_feature_start+'配图：</div></td><td ><input type="text" name="image_more_feature'+more_feature_start+
		'"  id="image_more_feature'+more_feature_start+'" style="width:400px;margin-top:20px; " /><input type="hidden" '+
		'name="more_feature_id'+more_feature_start+'" value="0" /><span style="color:#FF0000; '+
		'margin-left:20px;margin-top:20px;">(备注：请填写URL绝对地址)</span></td></tr>');
		
		$("#more_feature_start").val(more_feature_start);
		if(more_feature_start == 8)
		{
			$("#add_more_feature").css('display','none');
		}
	}
}

function inarray(obj,arr)
{
	if(typeof obj == 'string')
	{
		for(var i in arr) 
		{
			if(arr[i] == obj) 
			{
				return true;
			}
		}
	}
	return false;
} 

function  product_form_submit()
{
	var feature_start = parseInt($("#feature_start").val());
	var more_feature_start = parseInt($("#more_feature_start").val());
	
	var  products_id = $("#products_id").val();
	var  product_name = $("#product_name").val();
	var  cat_id  = $("#parent_id").val();
	var  pic_url = $("#pic_url").val().replace(/(^\s*)|(\s*$)/g, "");
	var  box_pic = $("#box_pic").val().replace(/(^\s*)|(\s*$)/g, "");
	var  type = $("#type").val();
	
	if(type == 'add')
	{
		if(products_id.replace(/(^\s*)|(\s*$)/g, "")=="")
		{
			alert("请输入产品ID!");
			$("#products_id").focus();
			return false;
		}
	
		if(cat_id.replace(/(^\s*)|(\s*$)/g, "")=="0")
		{
			alert("请选择产类别!");
			$("#parent_id").focus();
			return false;
		}
	
		if(pic_url1.replace(/(^\s*)|(\s*$)/g, "")=="")
		{
			alert("请填写产品配图1!");
			$("#pic_url1").focus();
			return false;
		}
	
	}
	return true;	 
}
